<%@ page import="cn.java71.dao.AdminDao" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="cn.java71.util.MyBatisUtil" %>
<%@ page import="cn.java71.entity.Admin" %><%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2021/1/25
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
  <%
      //session.getLastAccessedTime()//最后访问的时间
      //session.getMaxInactiveInterval()//失效的最大间隔时间

    request.setCharacterEncoding("utf-8");
    String name=request.getParameter("userName");
    String pass=request.getParameter("userPass");
    //>>>
      //userDatabase
      SqlSession session1= MyBatisUtil.get();

      AdminDao dao=session1.getMapper(AdminDao.class);
      Admin admin=dao.login(name,pass);
      MyBatisUtil.close(session1);
      if(admin!=null){
          session.setAttribute("LOGIN_USER",admin);
          Cookie c=new Cookie("user-name",name);
          c.setMaxAge(86400*7);
          response.addCookie(c);
          response.sendRedirect("welcome.jsp");
          return;

      }
    ///no database
//    if(name.startsWith("java71")&&pass.equals("123456")){
//        //登录成功后放入session
//        session.setAttribute("LOGIN_USER",name);
//        //cookie长期存放用户名
//        Cookie c=new Cookie("user-name",name);
//        c.setMaxAge(86400*7);
//        response.addCookie(c);
//        response.sendRedirect("welcome.jsp");
//        return;
//    }
    request.getRequestDispatcher("fail.jsp").forward(request,response);
  %>
</body>
</html>
